package com.querie.config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class Configuration {

	private static double lamda = 0.9;
	private static int numOfIterations = 10;
	private static int numOfFeatures = 25;
	private static int numOfFolds = 10;
	private static String testInputDir = "resources/folds";
	private static String importanceScheme = "ABSOLUTE";
	private static String ratingScheme = "LOG";
	private static int kValForFragments = 5;
	private static int mValForSession = 5;
	private static int nValForQuery = 5;
	private static String filterQuery = "from querylog";
	
	static
	{
		Properties prop = new Properties();
        //load a properties file
		try {
			prop.load(new FileInputStream("resources/system.properties"));	
			
			if (prop.getProperty("MF.LAMBDA") != null)
			{
				lamda = Double.parseDouble(prop.getProperty("MF.LAMBDA"));
			}
			if (prop.getProperty("MF.NUMOFFEATURES") != null)
			{
				numOfFeatures = Integer.parseInt(prop.getProperty("MF.NUMOFFEATURES"));
			}
			if (prop.getProperty("MF.NUMOFITERATIONS") != null)
			{
				numOfIterations = Integer.parseInt(prop.getProperty("MF.NUMOFITERATIONS"));
			}
			if (prop.getProperty("EVALUATION.NUMOFFOLDS") != null)
			{
				numOfFolds = Integer.parseInt(prop.getProperty("EVALUATION.NUMOFFOLDS"));
			}
			if (prop.getProperty("EVALUATION.INPUTDIR") != null)
			{
				testInputDir = prop.getProperty("EVALUATION.INPUTDIR");
			}
			if (prop.getProperty("EVALUATION.FRAGMENTIMPORTANCESCHEME") != null)
			{
				importanceScheme = prop.getProperty("EVALUATION.FRAGMENTIMPORTANCESCHEME");
			}			
			if (prop.getProperty("MF.RATINGSCHEME") != null)
			{
				ratingScheme = prop.getProperty("MF.RATINGSCHEME");
			}
			if (prop.getProperty("EVALUATION.KVALFORTOPFRAGMENTS") != null)
			{
				kValForFragments = Integer.parseInt(prop.getProperty("EVALUATION.KVALFORTOPFRAGMENTS"));
			}
			if (prop.getProperty("EVALUATION.MVALFORTOPSESSION") != null)
			{
				mValForSession = Integer.parseInt(prop.getProperty("EVALUATION.MVALFORTOPSESSION"));
			}
			if (prop.getProperty("EVALUATION.NVALFORTOPQUERY") != null)
			{
				nValForQuery = Integer.parseInt(prop.getProperty("EVALUATION.NVALFORTOPQUERY"));
			}
			
			if (prop.getProperty("EVALUATION.FILTERQUERY") != null)
			{
				filterQuery = prop.getProperty("EVALUATION.FILTERQUERY");
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	public static double getLamda() {
		return lamda;
	}
	public static int getNumOfIterations() {
		return numOfIterations;
	}
	public static int getNumOfFeatures() {
		return numOfFeatures;
	}
	public static int getNumOfFolds() {
		return numOfFolds;
	}
	public static String getTestInputDir() {
		return testInputDir;
	}
	
	public static String getImportanceScheme() {
		return importanceScheme;
	}
	public static boolean isLogRatingScheme()
	{
		return ratingScheme.equals("LOG");
	}
	public static boolean isRelativeImporanceScheme()
	{
		return importanceScheme.equals("RELATIVE");
	}
	public static String getRatingScheme() {
		return ratingScheme;
	}
	public static int getkValForFragments() {
		return kValForFragments;
	}
	public static int getmValForSession() {
		return mValForSession;
	}
	public static int getnValForQuery() {
		return nValForQuery;
	}
	public static void main(String a[])
	{
		System.out.println(Configuration.isLogRatingScheme());
	}
	
	public static String getConfigurationString()
	{
		String result = new String();
		
		result = "Matrix_Factorization: Lambda,"+lamda+"\n"+
				"Matrix_Factorization: Number Of Iterations,"+numOfIterations+"\n"+
				"Matrix_Factorization: Number Of Factors,"+numOfFeatures+"\n"+
				"Matrix_Factorization: Rating Scheme,"+ratingScheme+"\n"+
				"Evaluation: Importance Scheme,"+importanceScheme+"\n"+
				"Evaluation: Number Of Folds,"+numOfFolds+"\n"+
				"Evaluation: Test Input Directory,"+testInputDir+"\n"+
				"Evaluation: K Value for Top Fragments,"+kValForFragments+"\n"+
				"Evaluation: M Value for Top Sessions,"+mValForSession+"\n"+
				"Evaluation: N Value for Top Queries,"+nValForQuery+"\n";
		return result;
	}
	public static String getFilterQuery() {
		return filterQuery;
	}
	public static void setFilterQuery(String filterQuery) {
		Configuration.filterQuery = filterQuery;
	}
}
